<?php


function populateMenuItems($data, $log, &$menus)
{

if(sizeof($data) > 0)
{
	foreach($data as $row)
	{
		if($row['data'] != "")
		{
			$dataObj = json_decode($row['data']);
			$log->LogInfo("Processing item dataObj = " . print_r($dataObj, TRUE));
			
			switch($dataObj->type)
			{
				case "carousel1":
				{
					$obj = new stdClass();
					
					$obj->url = $dataObj->url;
					$obj->imageurl = $dataObj->imageurl;
					$obj->posttype = $dataObj->posttype;
					$obj->title = $dataObj->title;
					$obj->description = $dataObj->description;
					
					$obj->youtube_embed_id = $dataObj->youtube_embed_id;
					
					$menus->carousel1[] = $obj;
				}
				break;
				
				case "menu1":
				{
					$log->LogInfo("Processing menu1 items = " . print_r($dataObj, TRUE));
					
					foreach($dataObj->items as $item)
					{
						$log->LogInfo("Processing menu1 item = " . print_r($item, TRUE));
						
						$obj = new stdClass();

						$obj->name = $item->name;
					
						if(isset($item->link))
						{
							$obj->link = $item->link;
						}
										
						if(isset($item->submenus))
						{
							$obj->submenus = $item->submenus;
						}
					
						$menus->menu1[] = $obj;
					}
				}
				break;
				
				case "slider1":
				{
					$obj = new stdClass();
					$obj->url = $dataObj->url;
					
					if(isset($dataObj->clickurl))
					{
					   $obj->clickurl = $dataObj->clickurl;
					}
					
					$menus->slider1[] = $obj;
				}
				break;
				
				case "games":
				{
					$dataObj = json_decode($row['game_info']);
					$log->LogInfo("Processing item game dataObj = " . print_r($dataObj, TRUE));
			
					$obj = new stdClass();
					
					$obj->name = $dataObj->name;
					//$obj->email = $dataObj->email;
					$obj->gameinstructions = $dataObj->instructions;
					$obj->imageurl = '/Scratch/projects/' . $row['id'] . '/' . $dataObj->imagename;
					$obj->clickurl = '/scratchgame.php?gid=' . $row['id'];
					$obj->gametitle = $dataObj->gametitle;
					
					$menus->games[] = $obj;
				}
				break;
			}
		}
	}
}

}

?>